<!DOCTYPE html>
<html>
<head>

<link rel="stylesheet" type="text/css" href="../CssFrame/bootstrap-theme.css">
<link rel="stylesheet" type="text/css" href="../CssFrame/bootstrap.css">

<script src="../Jquery/Jquery-3.3.1.js" type="text/javascript"></script>
<script src="../Jquery/jquery.table2excel.js" type="text/javascript"></script>

<script src="../MySelfJS/CheckFunction.js" type="text/javascript"></script>

<meta charset="UTF-8">
<title>全体住宿生名单</title>

<style type="text/css">
th {
	text-align: center;
}
</style>
</head>
<body>
	<div style="text-align: center;">
		<h4 style="margin-top: 30px;">全部住宿生名单</h4>
		<div>
			<input type="button" value="导出为excel" class="btn btn-primary" onclick="table2Excel('住宿学生列表.xls')" />
			<table cellspacing="0" cellpadding="0" border="1" width="90%" id="mine_table" class="table2excel" 
				style="margin-left: 40px; margin-top: 2%;">
				<th>序号</th>
				<th>学号</th>
				<th>姓名</th>
				<th>楼号</th>
				<th>寝室号</th>
				<th>入住时间</th>
				<th class="noExcel">删除</th>
				<th class="noExcel">修改</th>

				<tbody id="stud_tab_body">

				</tbody>
			</table>
		</div>

		<div style="margin-top: 30px;">
			<a href="DormitoryManageSystem.html">返回系统导航页</a>
		</div>
	</div>
</body>

<script type="text/javascript">
	$(document).ready(function() {
		showStudsList();
	});

	/**
	 * 住宿生列表展示
	 */
	function showStudsList() {
		var url = "/dormitory/Students/show_stud_list";
		$.ajax({
			url : url,
			type : "GET",
			contentType : "application/json;cherset=utf-8",
			dataType : "json",
			success : function(j) {
				$("#stud_tab_body").empty();

				var list = j.data;

				var n = 1;

				if (list !== null) {
					//对list值进行遍历
					for (var index = 0; index <= list.length; index++) {
						var child = '<tr> <td>' + n++ + ' </td>' + '<td class="studentNo_item">#{studentNo}</td> '
								+ '<td class="studentName_item">#{studentName}</td> '
								+ '<td class="buildingNo_item">#{buildingNo}</td> '
								+ '<td class="chamberNo_item">#{chamberNo}</td> '
								+ '<td class="enterTime_item">#{enterTime}</td> '
								+ '<td class="noExcel"><a href="javascript:deleBySid(#{sid})">删除</a></td> '
								+ '<td class="noExcel"><a href="javascript:editBySid(#{sid})">修改</a></td>' + '</tr>';

						/*  */
						child = child.replace(/#{studentNo}/g, list[index].studentNo);

						child = child.replace(/#{studentName}/g, list[index].studentName);

						child = child.replace(/#{buildingNo}/g, list[index].buildingNo);

						child = child.replace(/#{chamberNo}/g, list[index].chamberNo);

						child = child.replace(/#{enterTime}/g, list[index].enterTime);

						child = child.replace(/#{sid}/g, list[index].sid);

						//将信息追加
						$("#stud_tab_body").append(child);
					}

				}
			}
		});
	}

	/**
	 * 删除student
	 */
	function deleBySid(sid) {
		var url = '/dormitory/Students/delete_stud';
		$.ajax({
			url : url,
			type : "POST",
			data : {
				'sid' : sid
			},
			dataType : "json",
			success : function(j) {
				if (j.state == 200) {
					alert('删除成功')
					location.reload()
				} else {
					alert(j.message)
				}
			}
		});
	}

	/**
	 * 将要修改的数据发送给后台
	 */
	function editBySid(sid) {
		var url = '/dormitory/Students/show_edit_stud';
		$.ajax({
			url : url,
			type : "POST",
			data : {
				'sid' : sid
			},
			dataType : "json",
			success : function(j) {
				if (j.state == 200) {
					location.href = "ExecuteEditStud.html";
				} else {
					alert(j.message)
				}
			}
		});
	}

	/* 导出为Excel表文件 */
	/**fileName导出的excel文件名,方法可带filename参数,亦可不带参数直接定义*/
	function table2Excel(fileName) {
		$(".table2excel").table2excel({
			exclude : ".noExcel",//class="noExl"的列不导出
			name : "Excel Document Name",
			filename : fileName,//文件名称
			fileext : ".xls",//文件后缀名
			//导出图片
			exclude_img : true,
			//导出超链接
			exclude_links : true,
			//导出输入框内容
			exclude_inputs : true
		});
	}
</script>
</html>